package RefactoringA1.src;

public class SavingsAccount {
	
	private CustomerData fData;
	private double fBalance;
	private static double interestRate = 1.25;
	private static int fNextAccountNumber = 0;
	
	public SavingsAccount(CustomerData the_customer)
	{
		fData = new CustomerData(the_customer.getfName(), the_customer.getfStreet(), 
				the_customer.getfZipCode(), the_customer.getfTown(), the_customer.getfCountry(),
				fNextAccountNumber);
		fNextAccountNumber++;
	}
	
	public void calculateInterest()
	{
		fBalance = fBalance + (fBalance * interestRate / 100);
	}
	
	/**
	 * 
	 * @param amount
	 * @return
	 */
	public boolean withdrawal(double amount)
	{
		boolean output = false;
		if(((fBalance - amount) > 0))
		{
			fBalance = fBalance - amount;
			output = true; 
		}
		return output;
	}
	
	public void verseMoney(double amount)
	{
		fBalance += amount;
	}
	
	/**
	 * ------Refactored------
	 * 
	 * Eliminated the System.out statements and added their Strings
	 * to the toString.
	 */
	public void print()
	{
		System.out.println(this.toString());
	}

	/**
	 * ------Refactored------
	 * 
	 * This method added to eliminate the System.out statements that were
	 * in the print() method.
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(fData.toString());
		sb.append("\nBalance:  " + fBalance);
		sb.append("\n**************************************");
		return sb.toString();
	}

}
